<!DOCTYPE html>
<html>
<head>
    {include file="public/head"}
</head>
<body>
<div class="g-flexview">
    <header class="m-navbar">
        <a href="javascript:history.back();" class="navbar-item">
            <i class="back-ico"></i>
        </a>
        <div class="navbar-center"><span class="navbar-title">修改密码</span></div>
    </header>
    <div class="g-scrollview">
        <form action="#" method="post">
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-left">手机号：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" autocomplete="off" value="{$user['phone']}" readonly id="phone"/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">验证码：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" placeholder="请输入验证码" autocomplete="off" name="code" id="code"/>
                        <button type="button" class="btn btn-warning" id="J_GetCode">获取验证码</button>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">新密码：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" placeholder="请输入新密码" autocomplete="off" name="new_password"/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">确认密码：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" placeholder="请再次输入新密码" name="new_password_1"/>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <button class="btn-block btn-primary modify_login_password" type="button">确认修改</button>
</div>
{include file="public/js"}
<script>
    !function ($) {
        var $getCode = $('#J_GetCode');
        /* 定义参数 */
        $getCode.sendCode({
            disClass: 'btn-disabled',
            secs: 60,
            run: false,
            runStr: '{%s}秒后重新获取',
            resetStr: '重新获取验证码'
        });
        $getCode.on('click', function () {
            /* ajax 成功发送验证码后调用【start】 */
            var $this = $(this);
            YDUI.dialog.loading.open('发送中');
            $.post('/api/sms/getValidateCode',{phone : $('#phone').val()},function (res) {
                dialog.loading.close();
                $this.sendCode('start');
                dialog.toast(res.msg, 'success', 1500);
            });
        });
        // 修改登录密码
        $('.modify_login_password').click(function () {
            dialog.confirm('提示','修改后旧密码将失效',function () {
                $.post('/api/sms/validateInputCode',{phone : $('#phone').val(),'code' : $('#code').val()},function (res) {
                    if (res.state == 'success'){
                        $.post('/index/set/loginPassword',$('form').serialize(),function (res) {
                            dialog.toast(res.msg,'none',1000);
                        });
                    }else {
                        dialog.toast(res.msg,'none',1000);
                    }
                });
            });
        });
    }(jQuery);
</script>
</body>
</html>